﻿using UnityEngine;
using System.Collections;

public class CarrierWoobleForward : MonoBehaviour {

	public Vector3 direction = new Vector3(-1.0f, -1.0f, 0.0f);
	public float speed = 1.0f;
	public float timeBetweenCycles = 800.0f;

	private float timeSinceLastCycle = 0.0f;
	private enum state {
		FORWARD,
		BACKWARD
	};
	state stateNow = state.FORWARD;

	// Use this for initialization
	void Start () {
		timeSinceLastCycle = timeBetweenCycles / 2.0f;
		direction.Normalize();
	}
	
	// Update is called once per frame
	void Update () {
		timeSinceLastCycle -= Time.deltaTime;
		if (timeSinceLastCycle < 0) {
			stateNow = stateNow == state.FORWARD ? state.BACKWARD : state.FORWARD;
			timeSinceLastCycle = timeBetweenCycles;
		}

		transform.localPosition += (stateNow == state.FORWARD ? direction : -direction) * speed*Time.deltaTime ;
	}
}
